/**
 * Created by yangjiao on 2019/6/28.
 */
import routerReport from './router-report.js'
import Blank from '@/components/public-modules/contact-summary/Blank.vue'
let popCount = 0
// 业务模块 start
const routers = [
  {
    path: '/login',
    name: 'login',
    component: () => import(/* webpackChunkName: "login" */ '@/components/business-modules/login/index.vue').then(m => m.default),
    meta: {
      title: 'login'
    }
  }, {
    path: '/index',
    component: () => import(/* webpackChunkName: "main" */ '@/components/ui-modules/index.vue').then(m => m.default),
    children: [
      {
        path: '',
        redirect: 'workbench'
      }, {
        path: 'call',
        component: () => import(/* webpackChunkName: "call" */ '@/components/business-modules/call/index.vue').then(m => m.default),
        children: [
          {
            path: '',
            component: Blank,
            meta: {
              title: 'callBlank'
            }
          },
          {
            path: '/index/call/:tabName',
            component: Blank,
            meta: {
              title: 'callBlank'
            }
          },
          {
            path: '/index/call/cdr_all/assginLeakSheetDetail',
            component: () => import(/* webpackChunkName: "call" */ '@/components/business-modules/call/AssginLeakSheetDetail.vue').then(m => m.default),
            meta: {
              title: 'misscall'
            }
          },
          {
            path: '/index/call/cdr_all/callExport',
            component: () => import(/* webpackChunkName: "call" */ '@/components/business-modules/call/CallExport.vue').then(m => m.default),
            meta: {
              title: 'bacthExportTask'
            }
          },
          {
            path: '/index/call/:tabType/:id/',
            component: () => import(/* webpackChunkName: "call" */ '@/components/business-modules/call/CallSummary.vue').then(m => m.default),
            meta: {
              title: 'callBlank'
            }
          },
          {
            // 当 /user/:id/profile 匹配成功，
            // UserProfile 会被渲染在 User 的 <router-view> 中
            path: '/index/call/:tabType/:id/cdr',
            component: () => import(/* webpackChunkName: "call" */ '@/components/business-modules/call/CdrCallSummaryAyna.vue').then(m => m.default),
            meta: {
              keepAlive: true,
              title: 'call'
            }
          },
          {
            path: '/index/call/:tabType/:id/outbound',
            component: () => import(/* webpackChunkName: "call" */ '@/components/business-modules/call/OutBoundSummaryAyna.vue').then(m => m.default),
            meta: {
              keepAlive: true,
              title: 'call'
            }
          }
        ]
      }, {
        path: 'km',
        component: () => import(/* webpackChunkName: "km" */ '@/components/business-modules/km/index.vue').then(m => m.default),
        children: [
          {
            path: 'blank',
            component: Blank,
            meta: {
              title: 'km'
            }
          },
          {
            path: 'import',
            component: () => import(/* webpackChunkName: "km" */ '@/components/business-modules/km/ImportTask.vue').then(m => m.default),
            meta: {
              title: 'km'
            }
          },
          {
            path: 'export',
              component: () => import(/* webpackChunkName: "km" */ '@/components/business-modules/km/ExportTask.vue').then(m => m.default),
              meta: {
              title: 'km'
            }
          },
          {
            path: 'quickReplyMain',
            component: () => import(/* webpackChunkName: "quickReplyMain" */ '@/components/business-modules/config/channelConfig/webchatGlobalConfig/quickReplyMain.vue').then(m => m.default),
            meta: {
              title: 'quickReplyMain'
            }
          },
          {
            path: '/index/km/:kmType/:kmId',
            component: () => import(/* webpackChunkName: "km" */ '@/components/business-modules/km/Km.vue').then(m => m.default),
            meta: {
              title: 'km'
            }
          }
        ],
        meta: {
          title: 'km'
        }
      }, {
        path: 'customer',
        component: () => import(/* webpackChunkName: "customer" */ '@/components/business-modules/customer/index.vue').then(m => m.default),
        meta: {
          title: 'customer'
        },
        children: [
          {
            path: '',
            component: Blank,
            meta: {
              title: 'customer'
            }
          },
          {
            path: '/index/customer/blank',
            component: Blank,
            meta: {
              title: 'customer'
            }
          },
          {
            path: '/index/customer/add',
            component: () => import(/* webpackChunkName: "customer" */ '@/components/business-modules/customer/AddCustomers.vue').then(m => m.default),
            meta: {
              title: 'addCustomer'
            }
          },
          {
            path: '/index/customer/merge',
            component: () => import(/* webpackChunkName: "customer" */ '@/components/business-modules/customer/MergeCustomers.vue').then(m => m.default),
            meta: {
              title: 'mergeCustomer'
            }
          },
          {
            path: '/index/customer/customize',
            component: () => import(/* webpackChunkName: "customer" */ '@/components/business-modules/customer/CustomizeFastSearch.vue').then(m => m.default),
            meta: {
              title: 'CustomizeFastSearch'
            }
          },
          {
            path: '/index/customer/export',
            component: () => import(/* webpackChunkName: "customer" */ '@/components/business-modules/customer/CustomizeExport.vue').then(m => m.default),
            meta: {
              title: 'export'
            }
          },
          {
            path: '/index/customer/listQuery',
            component: () => import(/* webpackChunkName: "customer" */ '@/components/business-modules/customer/CustomizelistQuery.vue').then(m => m.default),
            meta: {
              title: 'customizelistQuery'
            }
          },
          {
            path: '/index/customer/:tabType/:id',
            component: () => import(/* webpackChunkName: "customer" */ '@/components/business-modules/customer/CustSummary.vue').then(m => m.default),
            meta: {
              title: 'customer'
            }
          }
        ]
      }, {
        path: 'business',
        component: () => import(/* webpackChunkName: "business" */ '@/components/business-modules/business/index.vue').then(m => m.default),
        children: [
          {
            path: '',
            component: Blank,
            meta: {
              title: 'business'
            }
          },
          {
            path: '/index/business/customSearch',
            component: () => import(/* webpackChunkName: "business" */ '@/components/business-modules/business/CustomSearch.vue').then(m => m.default),
            meta: {
              title: 'business'
            }
          },
          {
            path: '/index/business/exportTask',
            component: () => import(/* webpackChunkName: "business" */ '@/components/business-modules/business/ExportTask.vue').then(m => m.default),
            meta: {
              title: 'business'
            }
          },
          {
            path: '/index/business/newBusiness',
            component: () => import(/* webpackChunkName: "business" */ '@/components/business-modules/business/newBusinessAndCustomer.vue').then(m => m.default),
            meta: {
              title: 'business'
            }
          },
          {
            path: '/index/business/:tabType/:id/:customerId',
            component: () => import(/* webpackChunkName: "business" */ '@/components/business-modules/business/BusinessSummary.vue').then(m => m.default),
            meta: {
              title: 'business'
            }
          }
        ]
      }, {
        path: 'ServiceBusinessList',
        component: () => import(/* webpackChunkName: "business" */ '@/components/business-modules/business/ServiceBusinessList.vue').then(m => m.default),
        meta: {
          title: 'business'
        }
      }, {
        path: 'email',
        component: () => import(/* webpackChunkName: "email" */ '@/components/business-modules/email/index.vue').then(m => m.default),
        children: [
          {
            path: '',
            component: Blank,
            meta: {
              title: 'email'
            }
          },
          {
            path: '/index/email/send_email',
            component: () => import(/* webpackChunkName: "email" */ '@/components/business-modules/email/SendEmailCon.vue').then(m => m.default),
            meta: {
              title: 'email'
            }
          },
          {
            path: '/index/email/:tabType/:id',
            component: () => import(/* webpackChunkName: "email" */ '@/components/business-modules/email/EmailSummary.vue').then(m => m.default),
            meta: {
              title: 'email'
            }
          },
          {
            path: '/index/email/:tabType/:id/email_jump',
            component: () => import(/* webpackChunkName: "email" */ '@/components/business-modules/email/EmailSummary.vue').then(m => m.default),
            meta: {
              title: 'email'
            }
          }
        ]
      }, {
        path: 'workbench',
        name: 'workbench',
        component: () => import(/* webpackChunkName: "workbench" */ '@/components/business-modules/workbenches/index.vue').then(m => m.default),
        meta: {
          title: 'workbench'
        }
      }, {
        path: 'report',
        name: 'report',
        component: () => import(/* webpackChunkName: "report" */ '@/components/business-modules/report/index.vue').then(m => m.default),
        meta: {
          title: 'report'
        },
        children: routerReport
      }, {
        path: 'monitor',
        name: 'monitor',
        component: () => import(/* webpackChunkName: "monitor" */ '@/components/business-modules/monitor.old/index.vue').then(m => m.default),
        meta: {
          title: 'monitor'
        }
      }, {  //  discover模块路由入口
        path: 'discover',
        name: 'discover',
        component: () => import(/* webpackChunkName: "monitorNew" */ '@/components/business-modules/discover/index.vue').then(m => m.default),
        meta: {
          title: 'discover'
        }
      }, {
        path: 'monitorNew',
        name: 'monitorNew',
        component: () => import(/* webpackChunkName: "monitorNew" */ '@/components/business-modules/monitor/index.vue').then(m => m.default),
        meta: {
          title: 'monitor'
        }
      }, {
        path: 'applications',
        name: 'applications',
        component: () => import(/* webpackChunkName: "monitorNew" */ '@/components/business-modules/applications/index.vue').then(m => m.default),
        meta: {
          title: 'applications'
        },
        children: [
          {
            path: 'applications/:id',
            component: () => import(/* webpackChunkName: "monitorNew" */ '@/components/business-modules/applications/index.vue').then(m => m.default),
          }
        ]
      },{
        path: 'questionnaire',
        component: () => import(/* webpackChunkName: "questionnaire" */ '@/components/business-modules/questionnaire/index.vue').then(m => m.default),
        meta: {
          title: 'questionnaire'
        },
        children: [
          {
            path: '',
            component: Blank,
            meta: {
              title: 'questionnaire'
            }
          },
          {
            path: '/index/questionnaire/:tabType/:id',
            component: () => import(/* webpackChunkName: "questionnaire" */ '@/components/business-modules/questionnaire/QuestionSummary.vue').then(m => m.default),
            meta: {
              title: 'questionnaire'
            }
          }
        ]
      }, {
        path: 'qualityCheck',
        name: 'qualityCheck',
        component: () => import(/* webpackChunkName: "qualityCheck" */ '@/components/business-modules/qualityCheck/index.vue').then(m => m.default),
        meta: {
          title: 'qualityCheck'
        },
        children: [
          {
            path: 'quality_check',
            redirect: 'quality_check/normal'
          },
          {
            path: 'quality_check/:tabTypes',
            component: () => import(/* webpackChunkName: "qualityCheck" */ '@/components/business-modules/qualityCheck/QualityCheck.vue').then(m => m.default),
            meta: {
              title: 'qualityCheck'
            }
          },
          {
            path: 'quality_check_result',
            component: () => import(/* webpackChunkName: "qualityCheck" */ '@/components/business-modules/qualityCheck/QualityCheckResult.vue').then(m => m.default),
            meta: {
              title: 'qualityCheck'
            }
          },
          {
            path: 'quality_check_agent',
            component: () => import(/* webpackChunkName: "qualityCheck" */ '@/components/business-modules/qualityCheck/QualityCheckAgent.vue').then(m => m.default),
            meta: {
              title: 'qualityCheck'
            }
          },
          {
            path: 'quality_check_task',
            component: () => import(/* webpackChunkName: "qualityCheck" */ '@/components/business-modules/qualityCheck/QualityCheckTask.vue').then(m => m.default),
            meta: {
              title: 'qualityCheck'
            }
          },
          {
            path: 'quality_check_cycle',
            component: () => import(/* webpackChunkName: "qualityCheck" */ '@/components/business-modules/qualityCheck/QualityCheckCycle.vue').then(m => m.default),
            meta: {
              title: 'qualityCheck'
            }
          }
        ]
      }, {
        path: 'intelligentQualityCheck',
        name: 'intelligentQualityCheck',
        component: () => import(/* webpackChunkName: "intelligentQualityCheck" */ '@/components/business-modules/intelligentQualityCheck/index.vue').then(m => m.default),
        meta: {
          title: 'intelligentQualityCheck'
        },
        children: [
          {
            path: 'quality_check',
            component: () => import(/* webpackChunkName: "intelligentQualityCheck" */ '@/components/business-modules/intelligentQualityCheck/QualityCheck.vue').then(m => m.default),
            meta: {
              title: 'intelligentQualityCheck'
            }
          },
          {
            path: 'quality_check_result',
            component: () => import(/* webpackChunkName: "intelligentQualityCheck" */ '@/components/business-modules/intelligentQualityCheck/QualityCheckResult.vue').then(m => m.default),
            name: 'qualityCheckResult',
            meta: {
              title: 'intelligentQualityCheck'
            }
          }
        ]
      }, {
        path: 'sms',
        name: 'sms',
        component: () => import(/* webpackChunkName: "sms" */ '@/components/business-modules/sms/index.vue').then(m => m.default),
        meta: {
          title: 'sms'
        },
        children: [
          {
            path: '',
            component: Blank,
            meta: {
              title: 'sms'
            }
          },
          {
            path: ':tabName/task/:id',
            component: () => import(/* webpackChunkName: "sms" */ '@/components/business-modules/sms/sms-import/smsImportDetail.vue').then(m => m.default),
            meta: {
              title: 'smsImportDetail'
            }
          },
          {
            path: ':tabName/addTemplate',
            component: () => import(/* webpackChunkName: "sms" */ '@/components/business-modules/sms/sms-import/smsImportAddTemplate.vue').then(m => m.default),
            meta: {
              title: 'smsImportDetail'
            }
          },
          {
            path: 'template',
            component: () => import(/* webpackChunkName: "sms" */ '@/components/business-modules/sms/SmsTemplate.vue').then(m => m.default),
            meta: {
              title: 'smsTemplate'
            }
          }
        ]
      }, {
        path: 'interface',
        name: 'urlInterface',
        component: () => import(/* webpackChunkName: "urlInterface" */ '@/components/business-modules/interface/index.vue').then(m => m.default),
        meta: {
          title: 'interface'
        }
      },{
        path: 'market',
        name: 'market',
        component: () => import(/* webpackChunkName: "market" */ '@/components/business-modules/market/index.vue').then(m => m.default),
        meta: {
          title: 'market'
        },
        children: [
          {
            path: 'marketing',
            component: () => import(/* webpackChunkName: "market" */ '@/components/business-modules/market/Marketing.vue').then(m => m.default),
            meta: {
              title: 'market'
            }
          },
          {
            path: 'searchKeyword',
            component: () => import(/* webpackChunkName: "market" */ '@/components/business-modules/market/SearchKeyword.vue').then(m => m.default),
            meta: {
              title: 'market'
            }
          },
          {
            path: 'customerAnalysis',
            component: () => import(/* webpackChunkName: "market" */ '@/components/business-modules/market/CustomerAnalysis.vue').then(m => m.default),
            meta: {
              title: 'market'
            }
          }
        ]
      }
    ]
  }, {
    path: '*',
    redirect: to => {
      // 方法接收 目标路由 作为参数
      // return 重定向的 字符串路径/路径对象
      popCount++
      if (to.query.sessionId) {
        window.sessionStorage.setItem('loginType', 'sessionId')
        window.sessionStorage.setItem('sessionId', to.query.sessionId)
        return './index/workbench'
      } else if (to.query.token) {
        window.sessionStorage.setItem('loginType', 'token')
        window.sessionStorage.setItem('loginToken', to.query.token)
        if (to.query.busyType) {
          window.sessionStorage.setItem('loginTokenBusyType', to.query.busyType)
        }
        return './index/workbench'
      } else if (to.path === '/') {
        return './login'
      }
      let path = to.path.split('/')
      for (let i = 0; i < popCount; i++) {
        path.pop()
      }
      return path.join('/')
    }
  }
]
export default routers
